﻿#region Copyright information
// 
// Copyright © 2005-2013 Yongkee Cho. All rights reserved.
// 
// This code is a part of the Biological Object Library and governed under the terms of the
// GNU Lesser General  Public License (LGPL) version 2.1 which accompanies this distribution.
// For more information on the LGPL, please visit http://bol.codeplex.com/license.
// 
// - Filename: ImputeWithConstant.cs
// - Author: Yongkee Cho
// - Email: yongkeecho@gmail.com
// - Date Created: 2012-09-06 11:39 AM
// - Last Modified: 2013-01-25 3:59 PM
// 
#endregion
using System;
using System.Collections.Generic;
using System.Linq;

namespace BOL.Linq.Transformation
{
    public static partial class Imputation
    {
        public static IEnumerable<decimal> ImputeWithConstant(this IEnumerable<decimal?> source, decimal constant)
        {
            return source.Select(x => x.HasValue ? x.Value : constant);
        }

        public static IEnumerable<double> ImputeWithConstant(this IEnumerable<double?> source, double constant)
        {
            return source.Select(x => x.HasValue ? x.Value : constant);
        }

        public static IEnumerable<float> ImputeWithConstant(this IEnumerable<float?> source, float constant)
        {
            return source.Select(x => x.HasValue ? x.Value : constant);
        }

        public static IEnumerable<int> ImputeWithConstant(this IEnumerable<int?> source, int constant)
        {
            return source.Select(x => x.HasValue ? x.Value : constant);
        }

        public static IEnumerable<long> ImputeWithConstant(this IEnumerable<long?> source, long constant)
        {
            return source.Select(x => x.HasValue ? x.Value : constant);
        }

        public static IEnumerable<decimal> ImputeWithConstant<TSource>(this IEnumerable<TSource> source, Func<TSource, decimal?> selector, decimal constant)
        {
            return source.Select(selector).ImputeWithConstant(constant);
        }

        public static IEnumerable<double> ImputeWithConstant<TSource>(this IEnumerable<TSource> source, Func<TSource, double?> selector, double constant)
        {
            return source.Select(selector).ImputeWithConstant(constant);
        }

        public static IEnumerable<float> ImputeWithConstant<TSource>(this IEnumerable<TSource> source, Func<TSource, float?> selector, float constant)
        {
            return source.Select(selector).ImputeWithConstant(constant);
        }

        public static IEnumerable<int> ImputeWithConstant<TSource>(this IEnumerable<TSource> source, Func<TSource, int?> selector, int constant)
        {
            return source.Select(selector).ImputeWithConstant(constant);
        }

        public static IEnumerable<long> ImputeWithConstant<TSource>(this IEnumerable<TSource> source, Func<TSource, long?> selector, long constant)
        {
            return source.Select(selector).ImputeWithConstant(constant);
        }
    }
}
